package com.ck.dp.FilterPattern.person;

import java.util.ArrayList;
import java.util.List;

import com.ck.dp.FilterPattern.person.domain.Person;
import com.ck.dp.FilterPattern.person.service.Criteria;
import com.ck.dp.FilterPattern.person.service.impl.AndCriteria;
import com.ck.dp.FilterPattern.person.service.impl.CriteriaFemale;
import com.ck.dp.FilterPattern.person.service.impl.CriteriaMale;
import com.ck.dp.FilterPattern.person.service.impl.OrCriteria;
/**
 * 过滤器模式
 * 例子：区分一个集合中是男性，女性，单身，单身并且是男性，单身或者还有女性的
 * @author admin
 *
 */
public class CriteriaPatternDemo {

	public static void main(String[] args) {
		List<Person> persons = new ArrayList<Person>();

		persons.add(new Person("Robert", "Male", "Single"));
		persons.add(new Person("John", "Male", "Married"));
		persons.add(new Person("Laura", "Female", "Married"));
		persons.add(new Person("Diana", "Female", "Single"));
		persons.add(new Person("Mike", "Male", "Single"));
		persons.add(new Person("Bobby", "Male", "Single"));
		
		Criteria male = new CriteriaMale();
		Criteria female = new CriteriaFemale();
		Criteria single = new CriteriaMale();
		Criteria singleMale = new AndCriteria(single, male);
		Criteria singleOrFemale = new OrCriteria(single, female);
		
		
		  System.out.println("Males: ");
	      printPersons(male.meetCriteria(persons));

	      System.out.println("\nFemales: ");
	      printPersons(female.meetCriteria(persons));

	      System.out.println("\nSingle Males: ");
	      printPersons(singleMale.meetCriteria(persons));

	      System.out.println("\nSingle Or Females: ");
	      printPersons(singleOrFemale.meetCriteria(persons));
		
	}

	
	
	public static void printPersons(List<Person> persons){
		for (Person person : persons) {
			System.out.println("Person : [ Name : " + person.getName() 
            +", Gender : " + person.getGender() 
            +", Marital Status : " + person.getMariralStatus()
            +" ]");
		}
	}
}
